package com.cl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cl.entity.EnterpriseAnnounce;
import com.cl.service.EnterpriseAnnounceService;
import com.cl.utils.DBUtils;

@Controller
public class EnterpriseController {

	 @Autowired 
	 private EnterpriseAnnounceService eas;
	
	/**
	 * @param EnterpriseAnnounce
	 * 保存职位发布信息到数据库
	 * 方法名规法为业务名
	 * @result String 发布结果
	 * **/
	@RequestMapping(value="job_posting",produces = "application/json;charset=UTF-8")
	public @ResponseBody String jobPosting(@RequestBody  EnterpriseAnnounce ea ){
		
		String rs = eas.job_posting(ea);
		return rs;
	}
	
	/**
	 * @param  work_district_prov 期望省  work_district_city 期望市  age_min最小年龄 age_max 
	 * 			最大年龄 keywords 关键字	sex性别 work_experience 工作经验  education_min 最低学历  
	 * 查询简历
	 * 方法名规法为业务名
	 * @result String 发布结果
	 * **/
	@RequestMapping(value="view_resume",produces = "application/json;charset=UTF-8")
	public @ResponseBody Map<String, Object> viewResume(@RequestParam(required=false,defaultValue="不限")  String  sex
			,@RequestParam(required=false,defaultValue="")  String  work_district_prov 
			,@RequestParam(required=false,defaultValue="")  String  work_district_city
			,@RequestParam(required=false,defaultValue="0")  String  age_min
			,@RequestParam(required=false,defaultValue="100")  String  age_max
			,@RequestParam(required=false,defaultValue="")  String  keywords
			,@RequestParam(required=false,defaultValue="不限")  String  work_experience
			,@RequestParam(required=false,defaultValue="不限")  String  education_min	
			){
		//拼接sql
		//等于不限  处理sex
		String sql = "select * from resume ";
		if(sex.equals("不限")) {
			sql += " where sex = '男' or sex = '女' ";
		}else {
			sql += "where sex = '"+sex+"' ";
		}
		if(work_district_prov != "") {
			sql+= " and expect_work_district_prov = "+work_district_prov+"' ";
		}
		 
		if(work_district_city != "") {
			sql+= " and expect_work_district_city = "+work_district_city+"' ";
		}
		
		sql+="and age>='"+age_min+"' and age <='"+age_max+"' ";
		
		if(keywords!="") {
			sql+= " and work_experience % '"+keywords+"%' ";
		}
		if(!work_experience.equals("不限")) {
			sql += "and  work_years >= '"+work_experience+"' ";
		}
		if(!education_min.equals("不限")) {
			sql += "and  education_level >= '"+education_min+"' "; //使用数字表示
		} 
		List<Map<String,Object>> ls  = DBUtils.queryForList(sql);
		
		Map<String,Object> rm = new HashMap<>();
		rm.put("code", 0);
		rm.put("msg", "");
		rm.put("count", 1000);
		rm.put("data",ls);
		
		return  rm;
	}
	
	@RequestMapping(value="table_test",produces = "application/json;charset=UTF-8")
	public @ResponseBody Map<String, Object> tableTest(@RequestParam(required=false,defaultValue="男")  String  sex ){
		
		List<Map<String,Object>> ls  = DBUtils.queryForList("select * from table_test where sex = '"+sex+"'");
		
		Map<String,Object> rm = new HashMap<>();
		rm.put("code", 0);
		rm.put("msg", "");
		rm.put("count", 1000);
		rm.put("data",ls);
		
		return  rm;
	}
	
	
}
